<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
    <title>管理员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <!-- load css -->
    <link rel="stylesheet" th:href="@{/css/font.css}" />
    <link rel="stylesheet" th:href="@{/css/xadmin.css}" />
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body class="layui-anim layui-anim-fadein">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a>管理员</a>
        <a><cite>管理员列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
          <input id="account" type="text" name="account"  placeholder="账号" autocomplete="off" class="layui-input">
          <div class="layui-input-inline">
            <select id="status" name="status">
              <option value="">全部</option>
              <option value="1">正常</option>
              <option value="0">禁用</option>
            </select>
          </div>
          <button id="searchBtn" data-type="reload" class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </div>
      </div>
      <xblock>
       <button class="layui-btn" onclick="x_admin_show('添加管理员','/admin/user/addPage.html',500,550)"><i class="layui-icon"></i>新增</button>
      </xblock>
      <table class="layui-hide" id="table1" lay-filter="tool1"></table>
      <script type="text/html" id="bar1">
  		<a class="layui-btn layui-btn-xs" lay-event="edit" onclick="x_admin_show('修改信息','/admin/user/updatePage.html?uid={{d.id}}',500,550)">修改</a>
		{{#  if(d.status == 1){ }}
 		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">禁用</a>
		{{#  }else{  }}
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="del">启用</a>
		{{#  }  }}
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reset">重置密码</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove">删除</a>
		</script>
      <!-- <div id="page" class="page"> -->
      </div>
<script type="text/html" id="statusTpl">
{{#  if(d.status == 1){ }}
<span style="color: green;">启用</span>
{{#  }else{  }}
<span style="color: red;">禁用</span>
{{#  }  }}
</script>
<script>

      layui.use(['laydate', 'laypage', 'table'], function(){
        var laydate = layui.laydate,
        table = layui.table,
        laypage = layui.laypage;
        table.render({
          elem: '#table1'
          ,height: 650
          ,limit: 15
          ,limits:[15,20,30,40,50,60,70,80,90]
          ,url: '[[@{/admin/user/list.html}]]' //数据接口
          ,id:'table1'
          ,page: true //开启分页
          ,cols: [
        	  [
            {field: 'id', title: 'ID', width:'10%', sort: true, align:'center'}
            ,{field: 'account', title: '账号', width:'19%', align:'center'}
            ,{field: 'name', title: '昵称', width:'20%', align:'center'}
            ,{field: 'remarks',  width:'20%',title: '备注'}
            ,{field: 'status', title: '状态', width: '10%',templet:'#statusTpl', align:'center'}
            ,{fixed: '', title: '操作', width: '20%', align:'center', toolbar: '#bar1'}
          ]
        	  ]
        });
        
        $('#searchBtn').on('click', function(){
        	var index = layer.msg('查询中，请稍候...',{icon: 16,time:false,shade:0});
        	table.reload('table1', {
    	        page: {
    	          curr: 1 //重新从第 1 页开始
    	        }
    	        ,where: {
    	            'account': $('#account').val(),
    	            'status':$('#status').val(),
    	        }
    	      });
        	layer.close(index);
       });
      
        
      //监听工具条
        table.on('tool(tool1)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data //获得当前行数据
          ,layEvent = obj.event; //获得 lay-event 对应的值
         if(layEvent === 'del'){
            layer.confirm('认真的吗', function(index){
              $.post('[[@{/admin/user/updateStatus.html}]]',{'id':data.id,'status':data.status},function(data){
            	  layer.close(index);
            	  if(data.code==0)
            	  {
            		  table.reload('table1', {
              	        page: {
              	          curr: 1 //重新从第 1 页开始
              	        }
              	        ,where: {
              	        	'account': $('#account').val(),
            	            'status':$('#status').val(),
            	            'name': $('#name').val(),
              	        }
              	      });
            	  }
            	  else
            	  {
            		  layer.msg('修改失败');
            	  }
              })
              //向服务端发送删除指令
            });
          }/*  else if(layEvent === 'edit'){
            layer.msg('编辑操作');
          } */
         if(layEvent === 'reset'){
             layer.confirm('确认重置吗', function(index){
               $.post('[[@{/admin/user/resetPassword.html}]]',{'id':data.id},function(data){
             	  layer.close(index);
             	  if(data.code==0)
             	  {
             		 layer.msg(data.msg);
             		  table.reload('table1', {
               	        page: {
               	          curr: 1 //重新从第 1 页开始
               	        }
               	        ,where: {
               	        	'account': $('#account').val(),
             	            'status':$('#status').val(),
             	            'name': $('#name').val(),
               	        }
               	      });
             	  }
             	  else
             	  {
             		  layer.msg('重置失败');
             	  }
               })
               //向服务端发送删除指令
             });
           }
         else if(layEvent === 'remove'){
       	  layer.confirm('确认删除?', function(index){
                 $.post('[[@{/admin/user/remove.html}]]',{'id':data.id},function(data){
               	  layer.close(index);
               	  if(data.code==0)
               	  {
               		  table.reload('table1', {
                 	        page: {
                 	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                 	        }
                 	        ,where: {
                 	        	'account': $('#account').val(),
                 	            'status':$('#status').val(),
                 	            'name': $('#name').val(),
                 	        }
                 	      });
               	  }
               	  else
               	  {
               		  layer.msg('删除失败');
               	  }
                 })
                 //向服务端发送删除指令
               });
         }
        });
        
      });



      function insert (argument) {
    	  layer.msg('代码还没写完!');
      } 
    </script>
  </body>
</html>
